package com.bookstore.controller;

import com.bookstore.model.Book;
import com.bookstore.service.ViewItemsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller

//图书管理
public class ViewItemsController {

    @Resource
    private ViewItemsService viewItemsService;

    //模糊查询、查询书籍
    @RequestMapping(value = "/find")
    public ModelAndView find(Book book){
        ModelAndView mv = new ModelAndView("ViewItems");
        List<Book> books = viewItemsService.find(book);
        mv.addObject("books",books);
        return mv;
    }


    //综合排序

    @RequestMapping(value = "/comprehensive")
    public ModelAndView comprehensive(Book book){
        ModelAndView mv = new ModelAndView("ViewItems");
        List<Book> books = viewItemsService.comprehensive(book);
        mv.addObject("books",books);
        return mv;
    }

    //好评
    @RequestMapping(value = "/WellReceived")
    public ModelAndView WellReceived(Book book){
        ModelAndView mv = new ModelAndView("ViewItems");
        List<Book> books = viewItemsService.WellReceived(book);
        mv.addObject("books",books);
        return mv;
    }

    //价格升序
    @RequestMapping(value = "/asc")
    public ModelAndView asc(Book book){
        ModelAndView mv = new ModelAndView("ViewItems");
        List<Book> books = viewItemsService.asc(book);
        mv.addObject("books",books);
        return mv;
    }

    //价格降序
    @RequestMapping(value = "/desc")
    public ModelAndView desc(Book book){
        ModelAndView mv = new ModelAndView("ViewItems");
        List<Book> books = viewItemsService.desc(book);
        mv.addObject("books",books);
        return mv;
    }

    //销量
    @RequestMapping(value = "/sales")
    public ModelAndView sales(Book book){
        ModelAndView mv = new ModelAndView("ViewItems");
        List<Book> books = viewItemsService.sales(book);
        mv.addObject("books",books);
        return mv;
    }


//    @RequestMapping(value = "/view")
//    public String view(){
//        return "ViewItems";
//    }

    //价格区间
    @RequestMapping(value = "/PriceRange")
    public ModelAndView PriceRange(Book book){
        ModelAndView mv = new ModelAndView("ViewItems");
        List<Book> books = viewItemsService.PriceRange(book);
        mv.addObject("books",books);
        return mv;
    }
}
